<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>SKU</th>
                    <th>产品名称</th>
                    <th>在库</th>
                    <th>站点在途</th>
                    <th>挪用数量</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{{ $transferP->sku->psku_code ?? '' }}</td>
                    <td>{{ $transferP->sku->psku_cn ?? '' }}</td>
                    <td>{{ $transferP->instant }}</td>
                    <td>{{ $transit }}</td>
                    <td>
                        <input type="text" class="transfer_num_"
                               style="width: 100px; text-align: right;"
                               name="transfer_num"
                               data-value="{{ max($transferP->instant,$transit,0) }}"
                               value="{{ 0 }}">
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div style="margin-top: 10px;">
    <div class="box-body fields-group">
        <div class="form-group">
            <div class="col-sm-10" style="margin-left: 25%">
                <button type="button" class="btn btn-primary" id="transfer-p-confirm-submit">提交</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('#transfer-p-confirm-submit').on('click', function() {
            $(this).prop('disabled',true);
            var transferNumObj = $('input[name="transfer_num"]');
            var max = transferNumObj.data('value');
            var transferNum = transferNumObj.val();
            // if(Number(transferNum) <= 0 ||Number(transferNum) > max){
            if(Number(transferNum) < 0 ||Number(transferNum) > max){
                $(this).prop('disabled',false);
                swal('数量有误', '', 'error');
                return false;
            }
            var id = "{{ $id }}";
            var iAreaId = "{{ $iAreaId }}";
            $.ajax({
                method: 'post',
                url: '/xqc/inventory/transfer-p-ajax',
                data: {
                    _token:"{{ csrf_token() }}",
                    action:"transferDeduct",
                    param:{ id:id,iarea_id:iAreaId,transfer_num:transferNum }
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                            $.pjax.reload('#transfer-p-confirm');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        });
        $(".transfer_num_").inputmask("integer",
            {
                onKeyValidation: function () {
                    var v = $(this).data('value');
                    if($(this).val() < 0 || $(this).val() > v){
                        $(this).val(0);
                    }
                }
            }
        );
    });
</script>
